<?php
declare (strict_types=1);

namespace app\exam\service;

use app\common\service\BaseService;
use Exception;
use app\exam\logic\{Paper as PaperLogic, PaperAnswer};
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Request;
use think\Response;

/**
 * 试卷服务类
 */
class Paper extends BaseService
{

    /**
     * 获取指定公开考试的试题基础信息
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-02-04
     *
     * @return Response [type] [description]
     */
    public function getPaperBase(): Response
    {
        $param = Request::get();
        $data  = app(PaperLogic::class)->getPaperBase($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取试题信息及选项
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-02-21
     *
     * @return Response [type] [description]
     */
    public function getPaperTopic(): Response
    {
        $param = Request::get();
        $data  = app(PaperLogic::class)->getPaperTopic($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 提交练习答案
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-02-21
     *
     * @return Response [type] [description]
     * @throws Exception
     */
    public function postPaperAnswer(): Response
    {
        $param = Request::post();
        $res   = app(PaperLogic::class)->postPaperAnswer($param);

        return $this->parseToData($res, 1, '提交成功');
    }

    /**
     * 获取用户公开考试记录列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-20
     *
     * @return Response [type] [description]
     */
    public function getUserExamRecordList(): Response
    {
        $param = Request::get();
        $data  = app(PaperAnswer::class)->getUserExamRecordList($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取用户指定试卷考试记录
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-20
     *
     * @return Response [type] [description]
     */
    public function getUserExamRecordInfo(): Response
    {
        $param = Request::get();
        $data  = app(PaperAnswer::class)->getUserExamRecordInfo($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取用户指定试卷考试记录错题解析
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-23
     *
     * @return Response [type] [description]
     */
    public function getUserExamWrongRecord(): Response
    {
        $param = Request::get();
        $data  = app(PaperAnswer::class)->getUserExamWrongRecord($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 错题重练获取试题及上下题
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-23
     *
     * @return Response [type] [description]
     */
    public function getWrongTopicWithAdjacent(): Response
    {
        $param = Request::get();
        $data  = app(PaperAnswer::class)->getWrongTopicWithAdjacent($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 考试结果试题信息
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-02-21
     *
     * @return Response [type] [description]
     */
    public function getTopicAnswerRecord(): Response
    {
        $param = Request::get();
        $res   = app(PaperAnswer::class)->getTopicAnswerRecord($param);

        return $this->parseToData($res, 1, '获取成功');
    }

    /**
     * 获取待批阅试卷列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-03
     *
     * @return Response [type] [description]
     */
    public function getUncorrectedPaper(): Response
    {
        $data = app(PaperAnswer::class)->getUncorrectedPaper();

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取待已阅试卷列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-03
     *
     * @param $type
     * @return Response [type] [description]
     */
    public function getPapers($type): Response
    {
        $data = app(PaperAnswer::class)->getPapers($type);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取试卷用户列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-03
     *
     * @return Response [type] [description]
     */
    public function getPaperUsers(): Response
    {
        $param = Request::get();
        $data  = app(PaperAnswer::class)->getPaperUsers($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 获取阅卷渲染数据
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-03
     *
     * @return Response [type] [description]
     */
    public function getPaperUserFetch(): Response
    {
        $param = Request::get();
        $data  = app(PaperAnswer::class)->getPaperUserFetch($param);

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 提交阅卷数据
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-04
     *
     * @return Response [type] [description]
     * @throws Exception
     */
    public function postPaperUserScore(): Response
    {
        $param = Request::post();
        $data  = app(PaperAnswer::class)->postPaperUserScore($param);

        return $this->parseToData($data, 1, '提交成功');
    }

    /**
     * 指派考试列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2023-07-07
     *
     * @return Response [type] [description]
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getPaperStudentList(): Response
    {
        $data  = app(PaperLogic::class)->getPaperStudentList();

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 购买考试列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2023-07-12
     *
     * @return Response [type] [description]
     * @throws DbException
     */
    public function getExamOrderList(): Response
    {
        $data  = app(PaperLogic::class)->getExamOrderList();

        return $this->parseToData($data, 1, '获取成功');
    }

    /**
     * 套卷试卷详情列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2023-07-12
     *
     * @param $id
     * @return Response [type] [description]
     * @throws DbException
     */
    public function getRollUpPaperList($id): Response
    {
        $data  = app(PaperLogic::class)->getRollUpPaperList($id);

        return $this->parseToData($data, 1, '获取成功');
    }

}
